﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

using ProjManagSolution.pmMyWebService;


//what to do? check the input function


namespace ProjManagSolution
{
    public partial class CreateProject : ChildWindow
    {
        protected user curUser = new user();

        public CreateProject(user cUser)
        {
            InitializeComponent();
            txtblokStartDate.Text = Convert.ToString(DateTime.Today);

            curUser = cUser;
        }

        protected bool Input_Validate()
        {
            if (txtboxProjectName.Text == "")
            {
                MessageBox.Show("Project name cannot be empty!");
                return false;
            }

            return true;
        }

        private void OKButton_Click(object sender, RoutedEventArgs e)
        {
            //on click
            pmWebServiceClient ws = new pmWebServiceClient();
            ws.GetProjectsCompleted += new EventHandler<GetProjectsCompletedEventArgs>(ws_GetProjectsCompleted);
            ws.GetProjectsAsync();
        }

        void ws_GetProjectsCompleted(object sender, GetProjectsCompletedEventArgs e)
        {
            //check existing project
            List<project> rl = e.Result;
            bool ProjectNameExist = false;
            for (int i = 0; i < rl.Count; ++i)
            {
                if (rl[i].project_name == txtboxProjectName.Text)
                {
                    ProjectNameExist = true;
                    break;
                }
            }

            if (ProjectNameExist)
            {
                MessageBox.Show("Project name exists!");
            }
            else
                if (Input_Validate())
                    this.DialogResult = true;
        }



        private void CancelButton_Click(object sender, RoutedEventArgs e)
        {
            this.DialogResult = false;
        }
    }
}


